<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author FIRE
-->
<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="true"
    @register="registerDrawer"
    @ok="handleSubmit"
    width="50%"
  >
    <template #title>
      <Icon :icon="getTitle.icon" class="pr-1 m-1" />
      <span> 确认图纸信息 </span>
    </template>
    <div style="font-weight: bold; margin-bottom: 10px; font-size: 18px">
      {{record.rsMsg}}
    </div>
    <a-divider />
    <div v-for="(item, index) in  record.list" :key="index" style="padding: 10px 0">
      <div v-if="item.checkResult">
        <div style="margin-bottom: 10px">
          <span style="font-size: 18px; font-weight: bold; margin-right: 20px"
            >{{ index + 1 }}、{{ item.picName }}</span
          >
        </div>
        <div style="margin-bottom: 5px">待发货数量：{{item.orderPic.iqty}} </div>
         <a-divider />
      </div>

      <div v-if="!item.checkResult">
        <div style="margin-bottom: 10px">
          <span style="color: red; font-size: 18px; font-weight: bold; margin-right: 20px"
            >{{ index + 1 }}、{{ item.picName }}</span
          >
        </div>
        <div style="margin-bottom: 5px">{{item.errorMsg}}</div>
         <a-divider />
      </div>
       
    </div>
  </BasicDrawer>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsM8RdRd01M8Rd01FormXzdd',
  });
</script>
<script lang="ts" setup>
  import { defineComponent, ref, computed, onMounted } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicForm, FormSchema, useForm } from '/@/components/Form';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { m8Rd01ScanPicAddRow } from '/@/api/m8/rd/rd01/m8Rd01';

  const emit = defineEmits(['success', 'register']);

  const { t } = useI18n('setting.pricemodel.wecharPriceModelInv');
  const { showMessage } = useMessage();
  const record = ref<WecharPriceModelUse>({} as WecharPriceModelUse);
  const getTitle = computed(() => ({
    icon: 'i-ant-design:book-outlined',
  }));
  let groupedMap = ref({});

  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (res) => {
    setDrawerProps({ loading: true });
    record.value = res
    // let data = res.data
    // for (const key in data) {
    //   if (data[key].length) {
    //     data[key].list = [data[key][0]];
    //   } else {
    //     data[key].list = [];
    //   }
    // }
    // groupedMap.value = data;
    record.value.__t = new Date().getTime();
    setDrawerProps({ loading: false });
  });

  async function handleSubmit() {
    let newArr =  record.value.list.filter(item=>{
      return item.checkResult
    })
    let arr =  newArr.map(item=>{
      return item.orderPic
    })

    // let obj = groupedMap.value;
    // let arr = [];
    // for (const key in obj) {
    //   obj[key].list.map((item) => {
    //     arr.push(item);
    //   });
    // }
    // console.log(arr);
    setTimeout(closeDrawer);
    emit('success', arr);
    
  }
</script>
